﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElingOA6_Admin_DSJCJ.Common;

namespace ElingOA6_Admin_DSJCJ.Areas.Admin.Controllers
{
    /// <summary>
    /// 绩效评估专栏类别定义
    /// </summary>
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class PerformanceFileClsController : Common.AdminBaseController
    {

        //
        // GET: /Admin/Performance/
        /// <summary>
        ///绩效评估专栏类别定义
        /// </summary>
        /// <returns>主页视图</returns>
        [AuthorityActionFilter("m_PerformanceFileCls", Order = 1)]
        [LogPageActionFilter("绩效评估专栏类别定义", Order = 2)]
        public ActionResult Index()
        {
            List<Model.PerformanceFileCls> codeNameList = new List<Model.PerformanceFileCls>();
            ViewData["blcode"] = true;
            codeNameList = GetCodeNameList();
            return View(codeNameList);
        }

        /// <summary>
        /// 获取编码数据列表
        /// </summary>
        /// <returns>数据集合</returns>
        private List<Model.PerformanceFileCls> GetCodeNameList()
        {
            BLL.PerformanceFileCls codeNameBll = new BLL.PerformanceFileCls();
            return codeNameBll.GetModelList("");
        }
        /// <summary>
        /// Grid调用方法
        /// </summary>
        /// <returns>Grid 视图</returns>
        public ActionResult PerformanceFileClsPartial()
        {
            List<Model.PerformanceFileCls> codeNameList = new List<Model.PerformanceFileCls>();

            codeNameList = GetCodeNameList();
            
            ViewData["blcode"] = true;
            return PartialView("PerformanceFileClsPartial", codeNameList);
        }

        /// <summary>
        /// 删除编码数据
        /// </summary>
        /// <param name="codeNo">编码编号</param>
        /// <param name="codeClsNO">编码类别编码</param>
        /// <returns>是否删除成功</returns>
        public string DelCode(string no)
        {
            string str = string.Empty;
            if (null != no)
            {
                no = Fetch.estimateString(no, CheckGetEnum.Safety);

                BLL.PerformanceFileCls codeNameBll = new BLL.PerformanceFileCls();
                try
                {
                    codeNameBll.Delete(no);
                    str = "ok";
                }
                catch (Exception)
                {
                    str = "error";
                }
            }
            return str;
        }

        /// <summary>
        /// 绩效评估专栏类别定义增加或修改页面
        /// </summary>
        /// <param name="no">编号（空为增加）</param>
        /// <returns>修改或增加视图</returns>
        public ActionResult PerformanceFileClsEdit(string no)
        {
            Model.PerformanceFileCls codeNameObj = new Model.PerformanceFileCls();
            ViewData["blcodeNo"] = true;
            if (null != no)
            {
                no = Fetch.estimateString(no, CheckGetEnum.Safety);
                BLL.PerformanceFileCls codeNameBll = new BLL.PerformanceFileCls();
                codeNameObj = codeNameBll.GetModel(no);
                if (null == codeNameObj)
                {
                    codeNameObj = new Model.PerformanceFileCls();
                }
                else
                {
                    ViewData["blcodeNo"] = false;
                }
            }

            return View(codeNameObj);
        }

        /// <summary>
        /// 编码保存
        /// </summary>
        /// <param name="codeNo">编码编号</param>
        /// <param name="codeName">编码名字</param>
        /// <param name="codeClsNo">编码类别编码</param>
        /// <param name="isAdd">是否添加true添加，false修改</param>
        /// <returns>是否添加成功</returns>
        public string CodeSave(string codeNo, string codeName, bool isAdd)
        {
            string str = string.Empty;

            codeNo = Fetch.estimateString(codeNo, CheckGetEnum.Safety);
            codeName = Fetch.estimateString(codeName, CheckGetEnum.Safety);

            BLL.PerformanceFileCls codeNameBll = new BLL.PerformanceFileCls();
            if (isAdd)//增加时判断编码是否已存在
            {
                if (codeNameBll.Exists(codeNo))
                {
                    return "exists";
                }
            }

            Model.PerformanceFileCls codeNameObj = new Model.PerformanceFileCls();
            codeNameObj.FPerformanceFileClsCd = codeNo;
            codeNameObj.FPerformanceFileClsName = codeName;

            try
            {
                if (isAdd)
                {
                    codeNameBll.Add(codeNameObj);
                }
                else
                {
                    codeNameBll.Update(codeNameObj);
                }
                str = "ok";

            }
            catch (Exception)
            {

                str = "error";
            }

            return str;
        }

    }
}
